<?php
namespace app\api\controller;

use app\BaseController;
// 用户登录API
class Login extends BaseController
{
	public function index(){
		if(!$this->request->isPost()){
			return show(config('status.error'),'非法请求');
		}
		$phoneNumber = $this->request->param("phone_number","","trim");
		$code = input("param.code",0,"intval");
		$type = input("param.type",0,"intval");
		// 参数校验
		$data = [
			'phone_number' => $phoneNumber,
			'code' => $code,
			'type' => $type,
		];

		$validate = new \app\api\validate\User();
		if(!$validate->scene('login')->check($data)){
			return show(config('status.error'),$validate->getError());
		}
		
		// 调用业务逻辑层
		$res = (new \app\common\business\User())->login($data);
		
		if($res){
			return show(config('status.success'),'登录ok',$res);
		}
		return show(config('status.error'),'登录失败');
	}
}